﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using System.IO;

namespace GlobalHooksTest
{
    public partial class ExclusionList : Form
    {
        OperatingSystemVersion sv = new OperatingSystemVersion();
        public ExclusionList()
        {
            InitializeComponent();
            if (sv.OSMajorVersion == 6)
            {
                this.BackColor = Color.Black;
                VistaControls.Dwm.DwmManager.EnableGlassSheet(this); 
            }
        }

        private void ExclusionList_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dS.Exclusion' table. You can move, or remove it, as needed.
            csSbar.Close();
            csSbar.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "\"" + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\SbarDB.mdb" + "\"";//""E:\Personal Projects\C#\Global Hook\GlobalHooksTest\bin\Debug\SbarDB.mdb"
            csSbar.Open();
            exclusionTableAdapter.Connection = csSbar;
            this.exclusionTableAdapter.Fill(this.dS.Exclusion);

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2) //Assuming the button column as second column, if not can change the index
            {
                //check if anything needs to be validated here
                if(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string NameofFile = Path.GetFileName(openFileDialog1.FileName);
                    dataGridView1.Rows[e.RowIndex].Cells[2].Value = NameofFile;
                }

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                bindingSource1.Position = bindingSource1.Position + 1;
            }
            catch
            {

            }
            exclusionTableAdapter.Update(dS.Exclusion);
            dS.AcceptChanges();
            this.exclusionTableAdapter.Fill(this.dS.Exclusion);
            frmSbarDevelopper.ExclusionList.Clear();
            foreach (DataRow dr in dS.Exclusion.Rows)
            {
                frmSbarDevelopper.ExclusionList.Add(dr["PATH"].ToString().ToLowerInvariant());
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            bindingSource1.MoveLast();
            bindingSource1.Position = bindingSource1.Position + 1;
        }

        private void button3_Click(object sender, EventArgs e)
        {
//            exclusionTableAdapter.Delete()
        }
    }
}
